﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using _MetalSlug.MyCharacters.Characters;
using _MetalSlug.Mission;

namespace _MetalSlug.Weapons.Units
{
    public class BazokaBullet : Bullet
    {
        public BazokaBullet()
        {
        }

        public BazokaBullet(Vector2 topleft, Vector2 size,Vector2 _Speed)
        {
            Type = TYPE_BULLET.BAZOKA_BULLET;
            InitialAttribute(topleft,size, _Speed);
        }

        public override void LoadContent()
        {
            List<Texture2D> Textures = GameUtil.LoadTextures("Weapon/BazokaBullet/", 3);
            MySprite temp = new MySprite(Textures, TopLeft);
            temp.Size = Size;
            Sprites.Add(temp);
        }

 
        public override void Draw(SpriteBatch spriteBatch)
        {
            Sprites[0].TopLeft = TopLeft;
            if (Visible == true)
            {
                base.Draw(spriteBatch);
            }
        }

        public override void Fire(Vector2 theStartPosition, Vector2 theDirection)
        {
            if (theDirection == -Vector2.UnitX)
            {
                TopLeft = new Vector2(theStartPosition.X - 30, theStartPosition.Y + 120);
                Sprites[0].Flip = MySprite.FLIPABLE.FLIP;
                Sprites[0].Rotation = 0;
            }

            if (theDirection == Vector2.UnitX)
            {
                TopLeft = new Vector2(theStartPosition.X + 120, theStartPosition.Y + 120);
                Sprites[0].Flip = MySprite.FLIPABLE.NOT_FLIP;
                Sprites[0].Rotation = 0;
            }

            if (theDirection == -Vector2.UnitY)
            {
                TopLeft = new Vector2(theStartPosition.X + 70, theStartPosition.Y - 10);
                Sprites[0].Rotation = 1.5f;
                Sprites[0].Flip = MySprite.FLIPABLE.FLIP;
            }

            StartPosition = theStartPosition;
            Direction = theDirection;
        }

        private float time = 0;
        public override void Update(GameTime gameTime, MyMap map, MyCharacter Hero)
        {
            if ((TopLeft.X >= Hero.TopLeft.X) && (TopLeft.X <= Hero.TopLeft.X + 100)&&
                    (TopLeft.Y >= Hero.TopLeft.Y) && (TopLeft.Y <= Hero.TopLeft.Y + 180))
            {
                Hero.Hp -= 10;     
                Visible = false;
            }
               
            if (Vector2.Distance(StartPosition, TopLeft) > 800)
            { 
                Visible = false;   
                   
            }
    
            if (Visible == true)
            {
                TopLeft += Direction * Speed * (float)gameTime.ElapsedGameTime.TotalSeconds;
                   
                    Sprites[0].nextFrame();
            }
            time++; 
        }

        public override Bullet Clone()
        {
            Bullet bazokaBullet = new BazokaBullet();
            bazokaBullet.Copy(this);
            return bazokaBullet;
        }

        public override void Copy(Bullet Origin)
        {
            base.Copy(Origin);
        }
    }

}
